package com.classroompie.classroompieserver.controller;

import com.classroompie.classroompiecommon.result.Result;
import com.classroompie.classroompiepojo.request.AddUserInput;
import com.classroompie.classroompieserver.service.TopicService;
import org.springframework.web.bind.annotation.*;

/**
 * @author jiahao
 * @since 2024/6/28 周五
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/topic")
public class TopicController {
    private final TopicService topicService;

    public TopicController(TopicService topicService) {
        this.topicService = topicService;
    }

    @PostMapping("/{courseId}/{title}")
    public Result<Object> addTopic(@PathVariable String courseId,@PathVariable String title) {
        topicService.addTopic(courseId,title);
        return Result.success();
    }

    @GetMapping("/{courseId}")
    public Result<Object> getTopic(@PathVariable String courseId) {
        return Result.success(topicService.getTopic(courseId));
    }

    @PostMapping("/message/{topicId}/{message}")
    public Result<Object> addMessage(@PathVariable String topicId,@PathVariable String message) {
        topicService.addMessage(topicId,message);
        return Result.success();
    }

    @GetMapping("/message/{topicId}")
    public Result<Object> getMessage(@PathVariable String topicId) {
        return Result.success(topicService.getMessage(topicId));
    }

    @GetMapping("/detail/{topicId}")
    public Result<Object> getTopicDetail(@PathVariable String topicId) {
        return Result.success(topicService.getTopicDetail(topicId));
    }
}
